package cn.hhy.hrm.controller;

import cn.hhy.hrm.domain.CourseDoc;
import cn.hhy.hrm.dto.CourseSearchParamDTO;
import cn.hhy.hrm.service.ICourseESService;
import cn.hhy.hrm.util.AjaxResult;
import cn.hhy.hrm.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/course")
public class CourseESController {

    @Autowired
    private ICourseESService courseESService;

    @PostMapping("/add")
    @PreAuthorize("hasAnyAuthority('es:saveCourse')")
    public AjaxResult add(@RequestBody CourseDoc doc){
        courseESService.add(doc);
        return AjaxResult.me();
    }



    @PostMapping("/searchCourse")
    public AjaxResult searchCourse(@RequestBody CourseSearchParamDTO dto){
        try {
            PageList<CourseDoc> pageList = courseESService.searchCourse(dto);
            return AjaxResult.me().setResultObj(pageList);
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }


    }

}
